<template>
	<view class="container">
		<!-- 用户信息 -->
		<view class="user-section">
			<view class="user-info">
				<image class="avatar" :src="userInfo.avatar || '/static/default-avatar.png'" mode="aspectFill" />
				<view class="info">
					<text class="nickname">{{ userInfo.nickname || '未登录' }}</text>
					<text class="id" v-if="userInfo.id">ID: {{ userInfo.id }}</text>
				</view>
			</view>
			<view class="user-stats">
				<view class="stat-item">
					<text class="num">{{ userInfo.followCount || 0 }}</text>
					<text class="label">关注</text>
				</view>
				<view class="stat-item">
					<text class="num">{{ userInfo.fansCount || 0 }}</text>
					<text class="label">粉丝</text>
				</view>
				<view class="stat-item">
					<text class="num">{{ userInfo.likeCount || 0 }}</text>
					<text class="label">获赞</text>
				</view>
			</view>
		</view>
		
		<!-- 订单信息 -->
		<view class="order-section">
			<view class="section-header">
				<text class="title">我的订单</text>
				<view class="more" @tap="viewAllOrders">
					<text>全部订单</text>
					<text class="iconfont icon-arrow-right"></text>
				</view>
			</view>
			<view class="order-types">
				<view class="type-item" v-for="item in orderTypes" :key="item.type" @tap="goToOrderList(item.type)">
					<text class="iconfont" :class="item.icon"></text>
					<text class="label">{{ item.label }}</text>
					<text class="badge" v-if="item.count">{{ item.count }}</text>
				</view>
			</view>
		</view>
		
		<!-- 功能列表 -->
		<view class="menu-list">
			<view class="menu-group">
				<view class="menu-item" v-for="item in menuItems" :key="item.id" @tap="handleMenuClick(item)">
					<text class="iconfont" :class="item.icon"></text>
					<text class="label">{{ item.label }}</text>
					<text class="iconfont icon-arrow-right"></text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userInfo: {
				avatar: '',
				nickname: '',
				id: '',
				followCount: 0,
				fansCount: 0,
				likeCount: 0
			},
			orderTypes: [
				{ type: 'unpaid', label: '待付款', icon: 'icon-wallet', count: 0 },
				{ type: 'unshipped', label: '待发货', icon: 'icon-box', count: 0 },
				{ type: 'shipped', label: '待收货', icon: 'icon-truck', count: 0 },
				{ type: 'completed', label: '已完成', icon: 'icon-check', count: 0 }
			],
			menuItems: [
				{ id: 1, label: '我的收藏', icon: 'icon-star' },
				{ id: 2, label: '收货地址', icon: 'icon-location' },
				{ id: 3, label: '客服中心', icon: 'icon-service' },
				{ id: 4, label: '设置', icon: 'icon-settings' }
			]
		}
	},
	onShow() {
		this.loadUserInfo()
		this.loadOrderCount()
	},
	methods: {
		async loadUserInfo() {
			try {
				// 这里替换为实际的API调用
				// const res = await this.$api.getUserInfo()
				// this.userInfo = res.data
			} catch (error) {
				console.error('加载用户信息失败', error)
			}
		},
		async loadOrderCount() {
			try {
				// 这里替换为实际的API调用
				// const res = await this.$api.getOrderCount()
				// this.orderTypes = this.orderTypes.map(item => ({
				//     ...item,
				//     count: res.data[item.type] || 0
				// }))
			} catch (error) {
				console.error('加载订单数量失败', error)
			}
		},
		viewAllOrders() {
			uni.navigateTo({
				url: '/pages/order/list'
			})
		},
		goToOrderList(type) {
			uni.navigateTo({
				url: `/pages/order/list?type=${type}`
			})
		},
		handleMenuClick(item) {
			switch (item.id) {
				case 1:
					uni.navigateTo({ url: '/pages/favorite/list' })
					break
				case 2:
					uni.navigateTo({ url: '/pages/address/list' })
					break
				case 3:
					uni.navigateTo({ url: '/pages/service/index' })
					break
				case 4:
					uni.navigateTo({ url: '/pages/settings/index' })
					break
			}
		}
	}
}
</script>

<style lang="scss">
.container {
	min-height: 100vh;
	background-color: #f5f5f5;
}

.user-section {
	background-color: #fff;
	padding: 40rpx 30rpx;
	margin-bottom: 20rpx;
	
	.user-info {
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
		
		.avatar {
			width: 120rpx;
			height: 120rpx;
			border-radius: 60rpx;
			margin-right: 30rpx;
		}
		
		.info {
			flex: 1;
			
			.nickname {
				font-size: 32rpx;
				color: #333;
				font-weight: bold;
				margin-bottom: 10rpx;
			}
			
			.id {
				font-size: 24rpx;
				color: #999;
			}
		}
	}
	
	.user-stats {
		display: flex;
		justify-content: space-around;
		
		.stat-item {
			text-align: center;
			
			.num {
				font-size: 32rpx;
				color: #333;
				font-weight: bold;
				margin-bottom: 8rpx;
			}
			
			.label {
				font-size: 24rpx;
				color: #999;
			}
		}
	}
}

.order-section {
	background-color: #fff;
	padding: 30rpx;
	margin-bottom: 20rpx;
	
	.section-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
		
		.title {
			font-size: 32rpx;
			color: #333;
			font-weight: bold;
		}
		
		.more {
			font-size: 24rpx;
			color: #999;
			
			.iconfont {
				margin-left: 8rpx;
			}
		}
	}
	
	.order-types {
		display: flex;
		justify-content: space-between;
		
		.type-item {
			position: relative;
			text-align: center;
			
			.iconfont {
				font-size: 48rpx;
				color: #333;
				margin-bottom: 8rpx;
			}
			
			.label {
				font-size: 24rpx;
				color: #666;
			}
			
			.badge {
				position: absolute;
				top: -8rpx;
				right: -8rpx;
				background-color: #ff6b6b;
				color: #fff;
				font-size: 20rpx;
				padding: 2rpx 8rpx;
				border-radius: 16rpx;
				min-width: 32rpx;
				text-align: center;
			}
		}
	}
}

.menu-list {
	background-color: #fff;
	
	.menu-group {
		.menu-item {
			display: flex;
			align-items: center;
			padding: 30rpx;
			border-bottom: 1rpx solid #f5f5f5;
			
			.iconfont {
				font-size: 40rpx;
				color: #333;
				margin-right: 20rpx;
				
				&.icon-arrow-right {
					margin-right: 0;
					margin-left: auto;
					font-size: 32rpx;
					color: #999;
				}
			}
			
			.label {
				font-size: 28rpx;
				color: #333;
			}
		}
	}
}
</style> 